
function bind(scope, fn) {
    return function () {
        fn.apply(scope, arguments);
    };
}



function Loader()
{
  this.scripts = Array();
  this.position = 0;
  this.total = 0;
  this.callback;
  
  this.load = function (src,callback)
  {
    if(callback)
      this.callback = callback;
      
    this.total++;
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = src;
    script.addEventListener('load',bind(this,this.loaded),true);
    head.appendChild(script); 
  }
    
  this.loaded = function ()
  {
    this.position++;
    
    if(this.isComplete() && this.callback != undefined)
      window[this.callback]();
  }
  
  this.isComplete = function ()
  {
    return this.position == this.total;
  }  
}

var loader = new Loader();

function include(src,callback)
{
  loader.load(src,callback);
}
